package com.malty.mall.domain.dto.req.pms;

import com.malty.mall.domain.entity.pms.PmsProductAttribute;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;

/**
 * @author malty
 */
@Data
@NoArgsConstructor
@ApiModel("商品属性")
public class PmsAttributeParam {
    private Long id;
    @ApiModelProperty("属性名称")
    @NotEmpty(message = "属性名不能为空")
    private String name;
    @ApiModelProperty("属性类型")
    private Long categoryId;
    @ApiModelProperty(value = "属性的类型；0->规格；1->参数")
    @Min(value = 0, message = "最小值0")
    @Max(value = 1, message = "最大值1")
    private Integer type;
    @ApiModelProperty("属性选择类型，唯一，单选，多选")
    private Integer selectType;
    @ApiModelProperty("属性录入方式， 手工录入 1 列表选择")
    private Integer inputType;
    @ApiModelProperty("可选值列表")
    private String inputList;
    @ApiModelProperty(value = "排序字段")
    private Integer sort;
    @Min(value = 0, message = "最小值0")
    @Max(value = 1, message = "最大值1")
    @ApiModelProperty(value = "分类筛选样式：1->普通；1->颜色")
    private Integer filterType;
    @Min(value = 0, message = "最小值0")
    @Max(value = 1, message = "最大值2")
    @ApiModelProperty(value = "检索类型；0->不需要进行检索；1->关键字检索；2->范围检索")
    private Integer searchType;
    @Min(value = 0, message = "最小值0")
    @Max(value = 1, message = "最大值1")
    @ApiModelProperty(value = "相同属性产品是否关联；0->不关联；1->关联")
    private Integer relateStatus;
    @Min(value = 0, message = "最小值0")
    @Max(value = 1, message = "最大值1")
    @ApiModelProperty(value = "是否支持手动新增；0->不支持；1->支持")
    private Integer handAddStatus;

    public PmsAttributeParam(PmsProductAttribute category) {
        if (category != null) {
            BeanUtils.copyProperties(category, this);
        }
    }

    public static List<PmsAttributeParam> attributeParams(List<PmsProductAttribute> records) {
        List<PmsAttributeParam> categoryParams = new ArrayList<>();
        for (PmsProductAttribute category : records) {
            categoryParams.add(new PmsAttributeParam(category));
        }
        return categoryParams;
    }
}
